﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Exhibition.Dao.ViewModel;
using AutoMapper;
namespace Exhibition.Dao{

   public class InviteDao     {


   public  InviteDao()   {
 
       Mapper.CreateMap<E_Invite, InviteModel>();
}
     public List<E_Invite> GetList(int startIndex, int maxRow, out int recordcount)
     {


       using(ExhibitionEntities edm=new ExhibitionEntities())
     {

         recordcount = edm.E_Invite.Count();

         return edm.E_Invite.OrderByDescending(s => s.Id).Skip(startIndex).Take(maxRow).ToList();

         }

     }


   public InviteModel GetOneById(int id)

   {


       using( ExhibitionEntities edm=new ExhibitionEntities())
    {

      var query= edm.E_Invite.FirstOrDefault(s => s.Id == id);
     return  Mapper.Map<E_Invite, InviteModel>(query);
   }

   }


   public int Save(InviteModel obj)
   {


       using( ExhibitionEntities edm=new ExhibitionEntities())
   {

       var query = edm.E_Invite.FirstOrDefault(s => s.Id == obj.Id);

         if (query == null)

         {


          query = new E_Invite();

         edm.AddToE_Invite(query);

         }


          query.InviteName=obj.InviteName;

          query.InviteType=obj.InviteType;

          query.CompName=obj.CompName;

          query.Email=obj.Email;

          query.Mobile=obj.Mobile;

          query.InviteNum=obj.InviteNum;

          query.LastInvite=obj.LastInvite;

          query.Result=obj.Result;

          query.FeedBack=obj.FeedBack;

          query.CreateTime=obj.CreateTime;
          query.CreateUserId = obj.CreateUserId;
       edm.SaveChanges();

       return query.Id;


   }

         }


   public int DelById(int id)
     {


       using( ExhibitionEntities edm=new ExhibitionEntities())
   {

       var query = edm.E_Invite.FirstOrDefault(s => s.Id == id);

          if (query != null)

            {


               edm.DeleteObject(query);


           }


         return edm.SaveChanges();


     }

     }


   }

 }

